
/* 
 * File:   RapidConfigManager.h
 * Author: dell
 *
 * Created on 2012年4月2日, 上午11:36
 */

#ifndef RAPIDCONFIG_H
#define	RAPIDCONFIG_H

#include <vector>

#include "../common.h"
#include "ServerConfig.h"
#include "ContextConfig.h"
#include "ContentTypeConfig.h"

#include "../dom/TinyXMLDocument.h"
#include "../dom/XMLElement.h"

namespace Rapid{
    class RapidConfigManager {
    public:
        RapidConfigManager();
        virtual ~RapidConfigManager();

        bool loadConfig(const char* globalConfigFileName, const char* serverConfigFileName);

        std::vector<ServerConfig*>* getServerConfigs();

    private:
        bool buildContextConfigs(ServerConfig* serverConfig, Try::XMLElement* serverCfg);

        bool buildAllWelcomeFiles(ServerConfig* serverConfig, ContextConfig* contextConfig, Try::XMLElement* contextCfg);

        bool buildWelcomeFiles(ServerConfig* serverConfig, ContextConfig* contextConfig, Try::XMLElement* welcomeFilesEL);

        bool buildContentTypeConfigs(ServerConfig* serverConfig, ContextConfig* contextConfig, Try::XMLElement* contextCfg);

        bool buildContentTypeConfigs(ContextConfig* contextConfig, Try::XMLElement* contextCfg, vector<Try::XMLElement*>& contentTypeELs);

        bool buildHeaders(ContentTypeConfig* contentTypeConfig, Try::XMLElement* contextCfg, Try::XMLElement* contentTypeCfg);

        bool buildHeaders(ContentTypeConfig* contentTypeConfig, vector<Try::XMLElement*>& headerELs);

        bool buildEngineConfig(ServerConfig* serverConfig, Try::XMLElement* serverCfg);

        bool buildCacheConfig(ServerConfig* serverConfig, Try::XMLElement* serverCfg);

        /** 检查是否重复 */
        bool containsWelcomeFile(ContextConfig* contextConfig, const char* wfile);

        /** 检查是否存在 */
        bool existWelcomeFile(ContextConfig* contextConfig, const char* wfile);

    private:
        Try::TinyXMLDocument globalDoc;
        Try::TinyXMLDocument serverDoc;

        std::vector<ServerConfig*> serverConfigs;
    };
}

#endif	/* RAPIDCONFIG_H */
